import pandas as pd

# 读取特征列表
feature_list_path = 'E:\\code\\611\\轻量化\\飞行数据\\selected_features.txt'
with open(feature_list_path, 'r', encoding='utf-8') as f:
    selected_features = [line.strip() for line in f.readlines()]  # 读取所有特征名

# **新的CSV文件路径**
new_file_path = 'E:\\code\\611\\轻量化\\飞行数据\\测试集test\\test1\\20_20220406_164358.csv'  # 需要筛选的新文件
output_path = 'E:\\code\\611\\轻量化\\飞行数据\\processed_test_2'  # 筛选后的输出文件

# 读取新CSV文件
new_data = pd.read_csv(new_file_path, encoding='UTF-8')
existing_features = [col for col in selected_features if col in new_data.columns]
# 筛选数据
filtered_data = new_data[existing_features]

# **保存筛选后的数据**
filtered_data.to_csv(f'{output_path}\\data_combine_2.csv', index=False, encoding='UTF-8')

print(f"已成功筛选特征，并保存至 {output_path}")
